using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;

namespace Speedball2 {
  public class DirBits {
    private BitVector32 _flags;

    private int _bit0_Up;
    private int _bit1_Down;
    private int _bit2_Left;
    private int _bit3_Right;
    //public int _bit4;
    //public int _bit5;
    //public int _bit6;
    //public int _bit7_button;

    public DirBits () {
      _bit0_Up = BitVector32.CreateMask ();
      _bit1_Down = BitVector32.CreateMask (_bit0_Up);
      _bit2_Left = BitVector32.CreateMask (_bit1_Down);
      _bit3_Right = BitVector32.CreateMask (_bit2_Left);
    }

    public DirBits (int flags)
      : this () {
      Init (flags);
    }

    public void Reset () {
      Init (0);
    }

    private void Init (int flags) {
      Bit0_IsUp = ((flags >> 0) & 1) == 1;
      Bit1_IsDown = ((flags >> 1) & 1) == 1;
      Bit2_IsLeft = ((flags >> 2) & 1) == 1;
      Bit3_IsRight = ((flags >> 3) & 1) == 1;
    }

    public bool Bit0_IsUp {
      get {
        return (_flags [_bit0_Up]);
      }
      set {
        _flags [_bit0_Up] = value;
      }
    }

    public bool Bit1_IsDown {
      get {
        return (_flags [_bit1_Down]);
      }
      set {
        _flags [_bit1_Down] = value;
      }
    }

    public bool Bit2_IsLeft {
      get {
        return (_flags [_bit2_Left]);
      }
      set {
        _flags [_bit2_Left] = value;
      }
    }

    public bool Bit3_IsRight {
      get {
        return (_flags [_bit3_Right]);
      }
      set {
        _flags [_bit3_Right] = value;
      }
    }

    public bool HasDirection {
      get {
        return (Bit0_IsUp || Bit1_IsDown || Bit2_IsLeft || Bit3_IsRight);
      }
    }

    public bool HasNoDirection {
      get {
        return (!Bit0_IsUp && !Bit1_IsDown && !Bit2_IsLeft && !Bit3_IsRight);
      }
    }

    public int Data {
      get {
        return (_flags.Data);
      }
    }
  }
}
